﻿<?php
include 'test_header.php';

class test_class_db_obj_topic extends UnitTestCase{
	
	private $db ; 

	function setUp(){

		$this->db = db_connect();

		$sql = "
CREATE TABLE IF NOT EXISTS `topic` (
  `title` varchar(1024) NOT NULL,
  `content` text NOT NULL,
  `problem_no` mediumint(9) ,
  `username` varchar(256) NOT NULL,
  `view_count` int(11) DEFAULT '0',
  `reply_count` int(11) DEFAULT '0',
  `post_time` datetime NOT NULL,
  `hot` tinyint(1) NOT NULL DEFAULT '0',
  `lock` tinyint(1) DEFAULT NULL
)		
		";

		$res = $this->db->query( $sql );
	}

	function tearDown(){
		
		$sql = "drop table topic";

		$res = $this->db->query( $sql );
	
	}

	function test_save_a_topic(){
	
		$db_obj_topic = new db_obj_topic( $this->db ) ;

		$db_obj_topic->set( 'problem_no' , '1001' );
		$db_obj_topic->set( 'title' , 'for test' );
		$db_obj_topic->set( 'content' , 'for test' );
		$db_obj_topic->set( 'username' , 'acm' ) ;
		$db_obj_topic->set( 'post_time' , '2010-10-1 22:22:22' ) ;

		$this->assertTrue( $db_obj_topic->save() );	
	}

}
	


$test = new test_class_db_obj_topic();
$test->run( new HtmlReporter() );

